<?php

namespace app\admin\controller;

use app\common\controller\Backend;

use think\Controller;
use think\Request;
use think\Db;

/**
 * 
 *
 * @icon fa fa-circle-o
 */
class Tender extends Backend
{
    
    /**
     * BorrowTender模型对象
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('BorrowTender');

    }

    public function index()
    {
        //设置过滤方法
        //$this->request->filter(['strip_tags', 'htmlspecialchars']);
        if ($this->request->isAjax())
        {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->where($where)->where('status != 0')->with('user,borrow')
                ->order($sort, $order)
                ->count();

            $list = $this->model
                ->where($where)->where('status != 0')->with('user,borrow')
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            foreach($list as $key=>$val){
                if($val['cardType']==0){
                    $list[$key]['cardType'] = '无';
                    $list[$key]['cardshouyi'] = '';
                    $list[$key]['totalmoney'] = $val['totalAccount'];
                }
                if($val['cardType']==1){
                    $list[$key]['cardType'] = '红包';
                    $list[$key]['cardshouyi'] = $val['redMoney'];
                    $list[$key]['totalmoney'] = $val['totalAccount']+$val['redMoney'];
                }
                if($val['cardType']==2){
                    $list[$key]['cardType'] = '加息卡';
                    $list[$key]['cardshouyi'] = $val['addInterest'];
                    $list[$key]['totalmoney'] = $val['totalAccount'] + $val['addInterest'];
                }
                if($val['borrow']['isDay']==1){
                    $list[$key]['borrowtime'] = $val['borrow']['time'].'天';

                }else{
                    $list[$key]['borrowtime'] = $val['borrow']['time'].'个月';
                }
            }


            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }
    

}
